package mzpd_server

import (
	"github.com/gogf/gf/v2/util/gconv"
	"io/ioutil"
	"mzpd_server/internal/logic/mzpd_server"
	"mzpd_server/internal/svc"
	"mzpd_server/internal/types"
	"net/http"

	"github.com/zeromicro/go-zero/rest/httpx"
)

func MZServiceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var req types.MZServiceRequest
		//if err := httpx.Parse(r, &req); err != nil {
		//	httpx.ErrorCtx(r.Context(), w, err)
		//	return
		//}
		s, _ := ioutil.ReadAll(r.Body) //把	body 内容读入字符串 s
		err2 := gconv.Struct(s, &req)
		if err2 != nil {
			httpx.ErrorCtx(r.Context(), w, err2)
			return
		}

		l := mzpd_server.NewMZServiceLogic(r.Context(), svcCtx)
		resp, err := l.MZService(&req)
		if err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
		} else {
			httpx.OkJsonCtx(r.Context(), w, resp)
		}
	}
}
